#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/EC2'
require 'basic_configuration'
require 'aws_context'
require 'pp'

# Create a snapshot.

if ARGV[0] == '-?' || ARGV.size != 1 then
	puts "usage: create-snapshot volume-id"
	exit 1
end
volume_id = ARGV[0]

Signal.trap("INT") do
  exit 2
end

config = BasicConfiguration.new
ec2 = AwsContext.instance.ec2(*config.keys)
begin
  res = ec2.create_snapshot(volume_id)
  puts "created #{res[:snapshot_id]}"
rescue
  puts "error #{$!} #{volume_id}"
  exit 1
end

